<template>
	<!-- 建设银行 -->
	<view>
		<view class="statusBar"></view>
		<view class="daohang">
			<view class="daohangicon" @tap="backBtn">❮</view>
			<view>账户明细</view>
			<view class="daohangicon"><span></span><span></span><span></span></view>
		</view>
		<view class="kaBg">
			<image src="../../static/bank-icon3.png" mode="widthFix"></image>
			<view>{{list.balance.bankCode.replace(/^(\w{4})\w{11}(.*)$/, '$1****$2')}}</view>
		</view>
		<view class="timeNav">
			<view>当天</view>
			<view>七天</view>
			<view class="status">一个月</view>
			<view>更多筛选</view>
		</view>
		<view class="tit">
			<view>{{myDatetime}}-{{year+'/'+month+'/'+day}}</view>
			<view>
				<view>
					<view>支出</view>
					<view>{{list.outAmount}}</view>
				</view>
				<view>
					<view>收入</view>
					<view>{{list.inAmount}}</view>
				</view>
			</view>
		</view>
		<view class="main">
			<view v-for="(item,index) in list.list" :key="index">
				<view>{{item.showDate.substr(6,1)}}月{{item.showDate.substr(8,2)}}日 {{item.week}}</view>
				<view class="mainList" v-for="(item1,index) in item.list" :key="index" @tap="delBtn" :data-id="item1.id">
					<view>
						<view style="font-size: 3.8vw;color: #333333;">{{item1.payTypeStr}}</view>
						<view style="font-size: 3.4vw;color: #999999;">{{item1.name}}</view>
					</view>
					<view>
						<view style="font-size: 3.8vw;" :class="item1.payType==0?'mygreen':'myred'">{{item1.payType==0?'-':'+'}}{{item1.showAmount}}</view>
						<view style="font-size: 3.8vw;color: #999999;">余额：{{item1.amount2}}</view>
					</view>
					<view style="font-size: 4.4vw;color: #999999;">❯</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const http = require('../../utils/http.js');
	export default {
		data() {
			return {
				id:null,
				list:null,
				year:null,
				month:null,
				day:null,
				myDatetime:null
			}
		},
		onLoad(options) {
			this.id=options.id
		},
		onShow() {
			var myDate=new Date();
			myDate.setMonth(myDate.getMonth()-1);
			this.myDatetime=myDate.getFullYear() + "/" + (myDate.getMonth()+1) + "/" + myDate.getDate()
			
			
			var now = new Date();
			this.year = now.getFullYear(); //年
			if((now.getMonth() + 1) < 10){ //月
				this.month = '0'+(now.getMonth() + 1)
			}else{
				this.month = now.getMonth() + 1;
			}
			if((now.getDate()) < 10){ //日
				this.day = '0'+now.getDate()
			}else{
				this.day = now.getDate();
			}
			uni.showLoading({
			    title: '加载中'
			});
			http.get('/api/balance/getBalanceDetail',{balanceId:this.id}).then(res => {
				//console.log(res.result.balance.bankCode)
				//console.log(res.result.balance.bankCode.replace(/^(\w{4})\w{10}(.*)$/, '$1***$2'))
				if (res.code == 200 && res.result) {
					this.list=res.result
				}
				uni.hideLoading();
			})
		},
		methods: {
			backBtn:function(){
				uni.navigateBack({
					delta: 1
				})
			},
			delBtn:function(e){
				var that=this
				uni.showModal({
				    title: '删除',
				    content: '确定删除该数据吗？',
				    success: function (res) {
				        if (res.confirm) {
				            //console.log(e.currentTarget.dataset.id);
							uni.showLoading({
							    title: '加载中'
							});
							http.get('/api/balance/delBalanceDetail',{balanceDetailId:e.currentTarget.dataset.id}).then(res => {
								uni.showToast({
								  title: res.message,
								  icon: 'none'
								});
								if(res.code==200){
									http.get('/api/balance/getBalanceDetail',{balanceId:that.id}).then(res1 => {
										if (res1.code == 200 && res1.result) {
											that.list=res1.result
										}
									})
								}
								uni.hideLoading();
							})
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			}
		}
	}
</script>

<style>
	.statusBar{
		height: 6vw;
		background: #0ab7f3;
	}
	.status{
		color: #226bc7;
		border-bottom: 4px solid #226bc7;
	}
	.myred{
		color: #f0483d;
	}
	.mygreen{
		color: #2a9b3f;
	}
	.daohang{
		display: flex;
		align-items: center;
		justify-content: space-between;
		color: #FFFFFF;
		background: #0ab7f3;
		padding: 2.8vw 3vw;
	}
	.daohang .daohangicon{
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		font-size: 5vw;
		width: 8%;
		text-align: center;
	}
	.daohang .daohangicon>span{
		display: inline-block;
		width: 1.2vw;
		height: 1.2vw;
		border-radius: 20vw;
		background: #FFFFFF;
		margin-right: 1vw;
	}
	.daohang view:nth-child(2){
		text-align: center;
		font-weight: bold;
		font-family: sans-serif;
	}
	.kaBg{
		width: 100%;
		padding: 1.8vw 0 0.7vw 0;
		background: #f3f4f8;
		position: relative;
	}
	.kaBg image{
		width: 100%;
	}
	.kaBg>view{
		position: absolute;
		top: 12vw;
		left: 15.5vw;
		color: #FFFFFF;
		font-size: 5vw;
	}
	.timeNav{
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 0 6vw;
		border-bottom: 1px solid #F2F2F2;
		font-size: 3.6vw;
	}
	.timeNav view{
		padding: 3.6vw 0;
	}
	.tit{
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 4vw 0;
		border-bottom: 6px solid #F2F2F2;
	}
	.tit>view:nth-child(1){
		background: #f2f2f2;
		padding: 1vw 4vw;
		border-radius: 20vw;
		font-size: 3.4vw;
	}
	.tit>view:nth-child(2){
		width: 80%;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		margin-top: 6vw;
	}
	.tit>view:nth-child(2)>view{
		text-align: center;
		width: 50%;
	}
	.tit>view:nth-child(2)>view:nth-child(1){
		border-right: 1px solid #f2f2f2;
		color: #2a9b3f;
	}
	.tit>view:nth-child(2)>view:nth-child(2){
		color: #f0483d;
	}
	.tit>view:nth-child(2)>view:nth-child(1)>view:nth-child(1),.tit>view:nth-child(2)>view:nth-child(2)>view:nth-child(1){
		font-size: 3.6vw;
		margin-bottom: 0.6vw;
	}
	.tit>view:nth-child(2)>view:nth-child(1)>view:nth-child(2),.tit>view:nth-child(2)>view:nth-child(2)>view:nth-child(2){
		font-size: 5vw;
	}
	.main{
		padding: 0 6vw;
	}
	.main>view{
		border-bottom: 5px solid #F2F2F2;
		padding-top: 3vw;
	}
	.main>view>view:nth-child(1){
		font-weight: bold;
	}
	.main>view .mainList{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		padding-bottom: 4.2vw;
		border-bottom: 1px solid #F2F2F2;
	}
	.main>view .mainList:last-child{
		border-bottom: none;
	}
	.main>view .mainList>view:nth-child(2){
		flex: 1;
		text-align: right;
		margin-right: 6vw;
	}
	.main>view .mainList>view:nth-child(2)>view:nth-child(1),.main>view .mainList>view:nth-child(1)>view:nth-child(1){
		margin-top: 3.8vw;
		margin-bottom: 1.6vw;
	}
</style>
